package com.roubsite.cloud.menu.controller;

import com.roubsite.cloud.common.bean.Result;
import com.roubsite.cloud.common.bean.enums.CommonStatusCodeEnum;
import com.roubsite.cloud.common.userinfo.RCUserUtils;
import com.roubsite.cloud.common.userinfo.SecurityUserDetails;
import com.roubsite.cloud.menu.bean.MenuRouteBean;
import com.roubsite.cloud.menu.service.ISystemMenuService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("menu")
public class MenuController {
    @Autowired
    ISystemMenuService systemMenuService;
    @Resource
    RCUserUtils rcUserUtils;

    /**
     * 获取侧栏菜单和vue的路由信息
     * @param request
     * @return
     */
    @GetMapping("routes")
    public Result routes(ServerHttpRequest request){
        ServletServerHttpRequest as;
        SecurityUserDetails userDetails = rcUserUtils.getUserInfo(request);
        List<MenuRouteBean> systemMenuResponse = systemMenuService.getUserMenu("0",userDetails.getUserId());
        if(systemMenuResponse.isEmpty()){
            return Result.setResultStatusCode(CommonStatusCodeEnum.SUCCESS);
        }
        return Result.setData(systemMenuResponse.get(0).getChildren());
    }
}
